package com.hinnotek.amoeba.viewmodels

import androidx.lifecycle.viewModelScope
import com.hinnotek.amoeba.base.BaseBean
import com.hinnotek.amoeba.bean.old.AmibaPayByAmibaPayIdBean
import com.hinnotek.amoeba.bean.old.AmibaProjectListByOrgIdBean
import com.hinnotek.amoeba.bean.old.ProductListBean
import com.hinnotek.amoeba.repo.AmibaPayRepo
import com.lee.common.base.BaseViewModel
import com.lee.common.network.net.StateLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import okhttp3.RequestBody
import javax.inject.Inject

@HiltViewModel
class AmibaPayViewModel @Inject constructor(private val repository: AmibaPayRepo) :
    BaseViewModel() {

    private val amibaPayByAmibaPayIdData = StateLiveData<AmibaPayByAmibaPayIdBean>()
    fun getAmibaPayByAmibaPayId(amibaPayId: Int): StateLiveData<AmibaPayByAmibaPayIdBean> {
        viewModelScope.launch {
            repository.getAmibaPayByAmibaPayId(amibaPayId, amibaPayByAmibaPayIdData)
        }
        return amibaPayByAmibaPayIdData
    }

    private val amibaProjectListByOrgIdData =
        StateLiveData<MutableList<AmibaProjectListByOrgIdBean>>()
    fun getAmibaPayPageByUserId(
        applyUserId: Int,
        pageNo: Int,
        pageSize: Int
    ): StateLiveData<MutableList<AmibaProjectListByOrgIdBean>> {
        viewModelScope.launch {
            repository.getAmibaPayPageByUserId(
                applyUserId,
                pageNo,
                pageSize,
                amibaProjectListByOrgIdData
            )
        }
        return amibaProjectListByOrgIdData
    }


    private val productListData = StateLiveData<MutableList<ProductListBean>>()
    fun getProductList(): StateLiveData<MutableList<ProductListBean>> {
        viewModelScope.launch {
            repository.getProductList(productListData)
        }
        return productListData
    }


    private val baseData = StateLiveData<BaseBean>()
    fun addAmibaPay(body: RequestBody): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.addAmibaPay(body, baseData)
        }
        return baseData
    }


}